package model.diagram.part;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import model.diagram.providers.ModelElementTypes;

import org.eclipse.gef.Tool;
import org.eclipse.gef.palette.PaletteContainer;
import org.eclipse.gef.palette.PaletteGroup;
import org.eclipse.gef.palette.PaletteRoot;
import org.eclipse.gef.palette.ToolEntry;
import org.eclipse.gmf.runtime.diagram.ui.tools.UnspecifiedTypeConnectionTool;
import org.eclipse.gmf.runtime.diagram.ui.tools.UnspecifiedTypeCreationTool;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;

/**
 * @generated
 */
public class ModelPaletteFactory {

	/**
	 * @generated
	 */
	public void fillPalette(PaletteRoot paletteRoot) {
		paletteRoot.add(createEntities1Group());
		paletteRoot.add(createRelations2Group());
	}

	/**
	 * Creates "Entities" palette tool group
	 * @generated
	 */
	private PaletteContainer createEntities1Group() {
		PaletteGroup paletteContainer = new PaletteGroup(
				Messages.Entities1Group_title);
		paletteContainer.setId("createEntities1Group"); //$NON-NLS-1$
		paletteContainer.add(createSeriesPackage1CreationTool());
		paletteContainer.add(createSerie2CreationTool());
		paletteContainer.add(createActor3CreationTool());
		paletteContainer.add(createActorsPackage4CreationTool());
		paletteContainer.add(createEpisodesPackage5CreationTool());
		paletteContainer.add(createSeasonPackage6CreationTool());
		paletteContainer.add(createSeason7CreationTool());
		paletteContainer.add(createEpisode8CreationTool());
		paletteContainer.add(createRole9CreationTool());
		return paletteContainer;
	}

	/**
	 * Creates "Relations" palette tool group
	 * @generated
	 */
	private PaletteContainer createRelations2Group() {
		PaletteGroup paletteContainer = new PaletteGroup(
				Messages.Relations2Group_title);
		paletteContainer.setId("createRelations2Group"); //$NON-NLS-1$
		paletteContainer.add(createAggegation1CreationTool());
		paletteContainer.add(createAssociation2CreationTool());
		return paletteContainer;
	}

	/**
	 * @generated
	 */
	private ToolEntry createSeriesPackage1CreationTool() {
		ToolEntry entry = new ToolEntry(
				Messages.SeriesPackage1CreationTool_title,
				Messages.SeriesPackage1CreationTool_desc, null, null) {
		};
		entry.setId("createSeriesPackage1CreationTool"); //$NON-NLS-1$
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createSerie2CreationTool() {
		ArrayList<IElementType> types = new ArrayList<IElementType>(2);
		types.add(ModelElementTypes.SeriesPackage_2002);
		types.add(ModelElementTypes.Serie_2011);
		NodeToolEntry entry = new NodeToolEntry(
				Messages.Serie2CreationTool_title,
				Messages.Serie2CreationTool_desc, types);
		entry.setId("createSerie2CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(ModelElementTypes
				.getImageDescriptor(ModelElementTypes.SeriesPackage_2002));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createActor3CreationTool() {
		NodeToolEntry entry = new NodeToolEntry(
				Messages.Actor3CreationTool_title,
				Messages.Actor3CreationTool_desc,
				Collections.singletonList(ModelElementTypes.Actor_2010));
		entry.setId("createActor3CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(ModelElementTypes
				.getImageDescriptor(ModelElementTypes.Actor_2010));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createActorsPackage4CreationTool() {
		NodeToolEntry entry = new NodeToolEntry(
				Messages.ActorsPackage4CreationTool_title,
				Messages.ActorsPackage4CreationTool_desc,
				Collections.singletonList(ModelElementTypes.ActorsPackage_2001));
		entry.setId("createActorsPackage4CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(ModelElementTypes
				.getImageDescriptor(ModelElementTypes.ActorsPackage_2001));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createEpisodesPackage5CreationTool() {
		NodeToolEntry entry = new NodeToolEntry(
				Messages.EpisodesPackage5CreationTool_title,
				Messages.EpisodesPackage5CreationTool_desc,
				Collections
						.singletonList(ModelElementTypes.EpisodesPackage_2016));
		entry.setId("createEpisodesPackage5CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(ModelElementTypes
				.getImageDescriptor(ModelElementTypes.EpisodesPackage_2016));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createSeasonPackage6CreationTool() {
		NodeToolEntry entry = new NodeToolEntry(
				Messages.SeasonPackage6CreationTool_title,
				Messages.SeasonPackage6CreationTool_desc,
				Collections.singletonList(ModelElementTypes.SeasonPackage_2015));
		entry.setId("createSeasonPackage6CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(ModelElementTypes
				.getImageDescriptor(ModelElementTypes.SeasonPackage_2015));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createSeason7CreationTool() {
		NodeToolEntry entry = new NodeToolEntry(
				Messages.Season7CreationTool_title,
				Messages.Season7CreationTool_desc,
				Collections.singletonList(ModelElementTypes.Season_2012));
		entry.setId("createSeason7CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(ModelElementTypes
				.getImageDescriptor(ModelElementTypes.Season_2012));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createEpisode8CreationTool() {
		NodeToolEntry entry = new NodeToolEntry(
				Messages.Episode8CreationTool_title,
				Messages.Episode8CreationTool_desc,
				Collections.singletonList(ModelElementTypes.Episode_2008));
		entry.setId("createEpisode8CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(ModelElementTypes
				.getImageDescriptor(ModelElementTypes.Episode_2008));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createRole9CreationTool() {
		NodeToolEntry entry = new NodeToolEntry(
				Messages.Role9CreationTool_title,
				Messages.Role9CreationTool_desc,
				Collections.singletonList(ModelElementTypes.Role_2009));
		entry.setId("createRole9CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(ModelElementTypes
				.getImageDescriptor(ModelElementTypes.Role_2009));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createAggegation1CreationTool() {
		ArrayList<IElementType> types = new ArrayList<IElementType>(5);
		types.add(ModelElementTypes.SeriesPackSerie_4001);
		types.add(ModelElementTypes.ActorPackActor_4002);
		types.add(ModelElementTypes.SeasonsPackSeason_4003);
		types.add(ModelElementTypes.EpisodesPackEpisode_4004);
		types.add(ModelElementTypes.SerieRole_4005);
		LinkToolEntry entry = new LinkToolEntry(
				Messages.Aggegation1CreationTool_title,
				Messages.Aggegation1CreationTool_desc, types);
		entry.setId("createAggegation1CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(ModelElementTypes
				.getImageDescriptor(ModelElementTypes.SeriesPackSerie_4001));
		entry.setLargeIcon(ModelDiagramEditorPlugin
				.findImageDescriptor("/org.ProjectWithoutName.edit/icons/full/obj16/Aggregation.gif")); //$NON-NLS-1$
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createAssociation2CreationTool() {
		LinkToolEntry entry = new LinkToolEntry(
				Messages.Association2CreationTool_title,
				Messages.Association2CreationTool_desc,
				Collections
						.singletonList(ModelElementTypes.AssociationActorToSerie_4006));
		entry.setId("createAssociation2CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(ModelElementTypes
				.getImageDescriptor(ModelElementTypes.AssociationActorToSerie_4006));
		entry.setLargeIcon(ModelDiagramEditorPlugin
				.findImageDescriptor("/org.ProjectWithoutName.edit/icons/full/obj16/Association.gif")); //$NON-NLS-1$
		return entry;
	}

	/**
	 * @generated
	 */
	private static class NodeToolEntry extends ToolEntry {

		/**
		 * @generated
		 */
		private final List<IElementType> elementTypes;

		/**
		 * @generated
		 */
		private NodeToolEntry(String title, String description,
				List<IElementType> elementTypes) {
			super(title, description, null, null);
			this.elementTypes = elementTypes;
		}

		/**
		 * @generated
		 */
		public Tool createTool() {
			Tool tool = new UnspecifiedTypeCreationTool(elementTypes);
			tool.setProperties(getToolProperties());
			return tool;
		}
	}

	/**
	 * @generated
	 */
	private static class LinkToolEntry extends ToolEntry {

		/**
		 * @generated
		 */
		private final List<IElementType> relationshipTypes;

		/**
		 * @generated
		 */
		private LinkToolEntry(String title, String description,
				List<IElementType> relationshipTypes) {
			super(title, description, null, null);
			this.relationshipTypes = relationshipTypes;
		}

		/**
		 * @generated
		 */
		public Tool createTool() {
			Tool tool = new UnspecifiedTypeConnectionTool(relationshipTypes);
			tool.setProperties(getToolProperties());
			return tool;
		}
	}
}
